<template>
    <div class="propertyList">
      <div class="roleList_buttons">
          <propertyHeadSearch ref="propertyHeadSearch1" @getBuildingInfoList1="getBuildingInfoList1" level="1"/>
      </div>
      <Table ref="TableHeight" class="table" :max-height="onresizeHeight"  :columns="columns1" :data="data1" ></Table>
      <!-- 分页 -->
      <div class="pagePublicStyle" v-show="pageData.total > 0">
         <div class="totalCount">
             当前第 {{pageData.page}} 页， 
             当前第 {{(pageData.page-1)*pageData.rows+1}} 条到第 {{pageData.page*pageData.rows>pageData.total?pageData.total:pageData.page*pageData.rows}} 条，
             共 {{pageData.total}} 条
         </div>
        <Page :current="pageData.page" :total="pageData.total" :page-size-opts="pageData.pageSizeOpts" @on-change="pageOnChangeFun" @on-page-size-change="pageOnPageSizeChangeFun" show-elevator show-sizer />
      </div>
      <!-- table 头部筛选 -->
      <!-- <table_filter :options="options" @cancelFilterFun="cancelFilterFun" @okFilterFun="okFilterFun"></table_filter> -->
      <!-- 审核弹窗 -->
      <Modal v-model="checkMoudle" title="请进行审核" footer-hide>
        <div>
            <Form ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="120">
                <FormItem label="审核结果" prop="result">
                    <Select v-model="formValidate.result" placeholder="请选择审核结果">
                        <Option value="1">通过</Option>
                        <Option value="2">不通过</Option>
                    </Select>
                </FormItem>
                <FormItem label="审核建议" prop="desc" v-if="formValidate.result != 1">
                    <Input v-model="formValidate.desc" type="textarea" :autosize="{minRows: 2,maxRows: 5}" placeholder="请输入审核建议"></Input>
                </FormItem>
                <FormItem>
                    <Button type="primary" @click="handleSubmit('formValidate')">确定</Button>
                </FormItem>
            </Form>
        </div>
    </Modal>
     <building-log :propertyLogState="propertyLogState" v-if="propertyLogState" :logData="logData" @closePopup="closePopup"/>
    </div>
    
</template>
<script>
  import table_filter from '@/components/table_filter';
  import propertyHeadSearch from '@/components/buildingCheckcenter/propertyHeadSearch';
  import buildingLog from "@/components/buildingCheckcenter/buildingLog";
  import {getCheckBuildingList, getBuildingCheck} from "@/api/buildingCheckcenter";
  export default {
    components: {
      table_filter,
      propertyHeadSearch,
      buildingLog
    },
     props:{
        currentName:{
            type:String,
            default:'checkWait'
        },
        currentCheckStatus:{
            type:String,
            default:'2'
        },
        chengeNameStatus:{
            type:String,
            default:''
        }
    },
    data() {
     const ruleValidateName = (rule, data, callback) =>{
        if(!data || data.length>15)return callback("请输入不超过15个字符长度的部门名称")
      callback()
    }
     return {
          onresizeHeight: 0,
          pageData: {
            total: 3,
            page: 1,
            rows: 10,
            pageSizeOpts: [10, 30, 50]
          },
          checkMess:{
              title: '操作',
              key: 'address',
              fixed: 'right',
              width: 100,
              align: 'center',
              render: (h, params) => {
                return h('div', [
                  h('a', {
                    on: {
                      click: (e) => {
                        e.stopPropagation();
                        this.goCheck(params.row);
                      }
                    }
                  }, '审核'),

                ]);
              },
          },
          columns1: [
            {
              title: 'ID',
              key: 'buildingId',
              minWidth: 90,
            },
            {
              title: '楼盘',
              key: 'buildingAlias',
              minWidth: 180,
            },
            {
              title: '地址',
              key: 'areaName',
              minWidth: 240,
              render: (h, params) => {
                return h('div',[
                     h('div', `城市:${params.row.provinceName}/${params.row.cityName}`),
                     h('div', `地区:${params.row.areaName}/${params.row.streetName}`),
                ]) 
              },
            },
            {
              title: '物业类型',
              key: 'propertyTypes',
              minWidth: 160,
              align: 'center',
              render: (h, params) => {
                return h('div',this.propertyTypeChange(params.row.propertyTypes)) 
              },
            },
            {
             title: '销售状态',
             key:'salesStatus',
             align: 'center',
             minWidth: 100,
             render: (h, params) => {
                return h('div',params.row.salesStatus?this.$formatter.switchName('salesStatus',params.row.salesStatus)[0]:'---') 
             },
           },
           {
             title: '线上状态',
             align: 'center',
             key:'buildingStatus',
             width:'100',
              render: (h, params) => {
                return h('div',params.row.buildingStatus == 1?'上架':params.row.buildingStatus == 2?'下架':'待提交') 
             },
           },
           {
             title: '创建时间',
             align: 'center',
              key:'createTime',
              minWidth:200,
           },
           {
             title: '更新时间',
             align: 'center',
              key:'updateTime',
             minWidth:200,
           },
           {
               title: '日志',
               align: 'center',
               width: 100,
               fixed: 'right',
               render: (h, params) => {
                return h('div', [
                  h('a', {
                    on: {
                      click: (e) => {
                        e.stopPropagation();
                        this.goLog(params.row);
                      }
                    }
                  }, '查看日志'),
                ]);
              },
           },
            
          ],
          data1: [],
          ruleValidate: {
                result: [
                    { required: true, message: '请选择审核结果', trigger: 'blur' }
                ],
                desc: [
                    { required: true, message: '请填写审核建议', trigger: 'blur' },
                    { type: 'string', min: 5, message: '请填写不少于5个字的建议', trigger: 'blur' },
                    { type: 'string', max: 2000, message: '你的建议超出长度了', trigger: 'blur' }
                ]
          },
          formValidate:{
              result:'',
              desc:''
          },
         propertyLogState:false,
         logData:{},
         checkMoudle:false
   }
  },
    methods: {
      // 分页 页码改变事件
      pageOnChangeFun(page) {
        this.pageData.page = page;
        this.getBuildingInfoList1()
        console.log('pageOnChangeFun', page)
      },
      // 分页 每页条数改变事件
      pageOnPageSizeChangeFun(row) {
        this.pageData.rows = row;
        this.pageData.page = 1;
        this.getBuildingInfoList1()
      },
      // 初始化获取数据
      initData() {
        this.$nextTick(() => {
          this.onresizeHeight = window.innerHeight - this.$refs.TableHeight.$el.offsetTop - 100
        });

      },
      //获取楼盘审核列表
     getBuildingInfoList1(params={}){
       //1:已保存,但未提交审核 2:待审核(审核中) 3:一级审核通过 4:一级审核驳回 5:二级审核通过 6:二级审核驳回
       let {page,  rows} = this.pageData;
       params = Object.assign({page,rows,auditStatus:this.currentCheckStatus},params)
       console.log('请求列表参数',params)
       getCheckBuildingList(params).then(res=>{
           console.log("获取楼盘审核列表",res);
           this.data1 = res.list;
           this.pageData.total = res.total-0
       })
     },
    //转变物业类型
    propertyTypeChange(mess){
       console.log(mess);
      if(!mess)return '';
      mess = [...new Set(mess)];
      let newArray=[];
      mess.map(item=>{newArray.push(this.$formatter.switchName('propertyType',item))}) 
      return newArray.toString();
    },
    //关闭日志弹窗
    closePopup(){
       this.logData= {};
       this.propertyLogState = false;
     },
     //查看日志
     goLog(mess){
           this.logData= mess;
           this.propertyLogState = true;
     },
     //审核
     goCheck(mess){
        this.currentCheckId = mess.buildingId;
        console.log(mess);
        this.$router.push({
            path:'/operationsCenter/buildingCheckcenter/buildingCheckcenterMess',
            query:{
              bid: mess.buildingId,
              state: 'view',
              auditId:mess.auditId,
              checkType: this.$route.name == 'secondlevelCheckcenter'?2:1,
              cityCode:mess.cityCode,
              createId:mess.createrId
            }
        })
     },
      // 查看详情
     viewClick(val) {
         //this.editEmployee = true;
         //this.editEmployeeMess = val;
         this.$router.push({
             path:"/system_center/roleControl/roleControling",
             name: 'roleControling',
             params:{
               id:5
             }
         })
     },
      //编辑点击确定
      editEmployeeSure(name){
        this.$refs[name].validate((valid) => {
           if (valid) {
               console.log("成功")
               //调取变更部门接口
               //this.$refs[name].resetFields();
           } 
        })
      },
      //开启禁用人员确定按钮
      deleEmployeeSure(name){
         this.$refs[name].validate((valid) => {
           if (valid) {
               console.log("成功")
               this.deleEmployee = false;
               //调取变更部门接口
               //this.$refs[name].resetFields();
           } 
        }) 
      },
      //开启禁用人员
      openAuthority(mess){
          //调取权限接口
          console.log("调取权限接口")
      },
      //只有待审核状态才有审核按钮
      ifCheckButton(){
        let index = this.columns1.findIndex(item=>item.title == '操作');
         if(this.currentName == 'checkWait' && index<0){
           this.columns1.push(this.checkMess)
         }else if(this.currentName != 'checkWait' && index>0){
            this.columns1.splice(this.columns1.length-1,1)
         }
      }
    },
    computed: {

    },
    created() {
      // 初始化获取数据
      // console.log('测试111111')
      this.initData()
    },
    activated() {

    },
    deactivated() {

    },
    mounted() {
      window.onresize = () => {
        return (() => {
          setTimeout(() => {
            this.onresizeHeight = window.innerHeight - this.$refs.TableHeight.$el.offsetTop - 150
          }, 10);
        })();
      };
      this.getBuildingInfoList1()
      this.ifCheckButton()
    },
    watch: {
      chengeNameStatus(newValue){
        console.log(2222,newValue)
            this.getBuildingInfoList1()
        },
        currentName(newValue){
          console.log(3333,newValue)
          this.ifCheckButton()
        }
    },
  }
</script>
<style lang="scss">
  .propertyList{
    height: calc(100% - 20px);
    .allCustomersP{
      padding: 8px 14px;
    }
    &_buttons{
      margin: 20px;
      text-align: left; 
    }
   /deep/.ivu-table-wrapper{
       height: 100%;
   }
   /deep/.ivu-table th{
       background-color: #f6f8fa;
   }
   /deep/.ivu-form-item{
     margin-bottom: 12px;  
   }
  }
  /* page */
  .pagePublicStyle{
    text-align: right;
    padding: 14px 0;
    margin-right: 30px;
  }
  .totalCount{
    float: left;
    line-height: 34px;
    padding-left: 20px;  
  }
 .table {
  .ivu-modal-header {
    border-bottom: 1px solid #e8eaec;
    padding: 14px 16px;
    line-height: 1;
  }
  th .ivu-table-cell-with-selection{
    position: relative;
  }
  th .ivu-table-cell-with-selection::after{
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    background: #f8f8f9;
    z-index: 99;
  }
}
</style>
